<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script src="./axios.js"></script>
  <h2>基地址</h2>
  <button class="btn1">get</button>
  <button class="btn2">post</button>

  <script>
    axios.defaults.baseURL = 'http://ajax-api.itheima.net'
    document.querySelector('.btn1').onclick = function () {
      axios({
        url: '/api/news',
        method: 'get',
      }).then((res) => {
        console.log('res:', res)
      })
    }
    document.querySelector('.btn2').onclick = function () {
      axios({
        url: '/api/login',
        method: 'post',
        data: {
          username: 'admin',
          password: '123456',
        },
      }).then((res) => {
        console.log('res:', res)
      })
    }
  </script>
</body>

</html>